package GUI;

import swimming.VIPcard;
import use.consumeuse;
import use.VIPuse;
import use.consumptionuse;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;

public class usecard {
    private JPanel panel1;
    private JButton 会员卡充值Button;
    private JButton 新会员注册Button;
    private JButton 查询修改会员信息Button;
    private JButton 更改系统密码Button;
    private JButton 查询消费记录Button;
    private JButton 会员卡汇总记录Button;
    private JButton 使用会员卡Button;
    private JTextField TextField;
    private JButton 确定Button;
    private JTextField num;
    private JLabel totalmoney;
    private JButton 消费记录报表Button;

    public static void iface()
    {
        JFrame frame = new JFrame("游泳馆会员管理系统");
        frame.setSize(500, 400);
        frame.setLocation(400, 200);

        usecard t1 = new usecard();
        frame.add(t1.panel1);

        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    public usecard()   {
        会员卡充值Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new recharge().iface();
            }
        });
        查询消费记录Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new consume().iface();
            }
        });
        查询修改会员信息Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new revise().iface();
            }
        });
        更改系统密码Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new password().iface();
            }
        });
        新会员注册Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new VIP().iface();
            }
        });
        会员卡汇总记录Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new totalVIP().iface();
            }
        });
        使用会员卡Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new usecard().iface();
            }
        });
        确定Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                VIPuse vip=new VIPuse();
                consumptionuse co=new consumptionuse();
                consumeuse cos=new consumeuse();
                String[] a=new String[3];
                String[] b=new String[2];
                String[] c=new String[4];
                String[] d=new String[3];
                String q=null;
                String w=null;
                String p=null;
                double z;
                String money;
                double x1;
                double x2;
                List<?> state;
                Calendar calendar = Calendar.getInstance();
                SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                a[0]=formatter.format(calendar.getTime());
                //a[0]=textField1.getText();
                a[1]=TextField.getText();
                try {
                    List<VIPcard> list=vip.搜索(a[1]);
                    for (VIPcard v : list) {
                        q=v.getCardtype();
                        w=v.getState();
                        p=v.getMoney();//卡的金额折扣
                    }
                    if((w.equals("禁用")))
                    {
                        JOptionPane.showMessageDialog(null, "该卡已被禁用，暂时无法使用", "提示",
                                JOptionPane.INFORMATION_MESSAGE);
                    }
                    else if(q.equals("折扣卡"))
                    {
                            z= Double.valueOf(num.getText());
                            x1=Double.valueOf(z);
                            x2=Double.valueOf(p);
                            x1= x1 * 30 * x2 *0.01;
                            money=String.valueOf(x1);
                            a[2]=money;
                            state = co.折扣卡(a);
                            if(state == null)
                            {
                                JOptionPane.showMessageDialog(null, "非营业时间", "提示",
                                        JOptionPane.INFORMATION_MESSAGE);
                            }
                            else {
                                totalmoney.setText(money);
                                d[0] = TextField.getText();
                                d[1] = formatter.format(calendar.getTime());
                                //d[2]=textField1.getText();
                                d[2]=num.getText();
                                state = cos.增加(d);
                                JOptionPane.showMessageDialog(null, "欢迎再次光临", "提示",
                                        JOptionPane.INFORMATION_MESSAGE);
                            }

                    }
                    else if(q.equals("储值卡"))
                    {
                        z= Double.valueOf(num.getText());
                        x1=Double.valueOf(z);
                        x2=Double.valueOf(p);
                        x1=x2-(x1*30);
                        x2=z*30;
                        money=String.valueOf(x1);
                        b[0]=money;
                        b[1]=TextField.getText();
                        //b[1]=textField1.getText();
                        vip.使用vip(b);
                        c[0]=money;
                        //c[1]=textField1.getText();
                        c[1]=formatter.format(calendar.getTime());
                        c[2]=TextField.getText();
                        money=String.valueOf(x2);
                        c[3]=money;
                        state=co.储值卡(c);
                        if(state == null)
                        {
                            JOptionPane.showMessageDialog(null, "非营业时间", "提示",
                                    JOptionPane.INFORMATION_MESSAGE);
                        }
                        else{
                            totalmoney.setText(money);
                            d[0]=TextField.getText();
                            d[1]=formatter.format(calendar.getTime());
                            d[2]=num.getText();
                            cos.增加(d);
                            JOptionPane.showMessageDialog(null, "欢迎再次光临", "提示",
                                    JOptionPane.INFORMATION_MESSAGE);
                        }

                        //d[2]=textField1.getText();

                        //if(state == null)
                        //{
                        //    JOptionPane.showMessageDialog(null, "非营业时间", "提示",
                          //          JOptionPane.INFORMATION_MESSAGE);
                        //}
                    }

                } catch (SQLException ex) {
                    ex.printStackTrace();
                }
            }
        });
        消费记录报表Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new baobiao().iface();
            }
        });
    }
    public static void main(String[] args) {
        iface();
    }
}
